<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Minim : : Minim : : createRecorder</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="stylesheet.css" rel="stylesheet" type="text/css">
</head>
<body> 
<center>
<table class="mainTable">

  <tr>
    <td class="header">
    	<span class="indexheader">Minim</span><br/>
    	<span class="indexnavigation">
    		<a href="index.html">core</a> | 
    		<a href="index_ugens.html">ugens</a> | 
    		<a href="index_analysis.html">analysis</a>
    	</span>
    </td>
    <td class="border-left">&nbsp;</td>
  </tr>
  
  <tr>
    <td class="classNavigation">
    	<p class="mainTextName"><A href="minim_class_minim.html">Minim</A></p>
    	<p class="methodName">createRecorder</p>
    </td>
    <td class="mainText border-left">
    	<p class="memberSectionHeader">Description</p>
    	Creates an AudioRecorder that will use the provided Recordable object as its
 record source and that will save to the file name specified. Recordable 
 classes in Minim include AudioOutput, AudioInput, AudioPlayer, and AudioSample.
 The format of the file will be inferred from the extension in the file name. 
 If the extension is not a recognized file type, this will return null.
    	
    	<p class="memberSectionHeader">Signature</p>
    	<pre>AudioRecorder createRecorder(Recordable source, String fileName)
</pre>
    	
    	
   <p class="memberSectionHeader">Parameters</p>
   
        <span class="parameterName">source</span>&nbsp;&mdash;&nbsp;<span class="parameterDescription">the <code>Recordable</code> object you want to use as a record source</span><br/>
    
        <span class="parameterName">fileName</span>&nbsp;&mdash;&nbsp;<span class="parameterDescription">the name of the file to record to</span><br/>
    
   
    	
   <p class="memberSectionHeader">Returns</p> 
   <p>an <code>AudioRecorder</code> for the record source</p>
   
    	
    	<p class="memberSectionHeader">Related</p>
    	<A href="audiorecorder_class_audiorecorder.html">AudioRecorder</A><BR>

    	
    	<p class="memberSectionHeader">Example</p>
    	<pre>/**
  * This sketch demonstrates how to use an &lt;code>AudioRecorder&lt;/code> to record audio to disk. 
  * Press 'r' to toggle recording on and off and the press 's' to save to disk. 
  * The recorded file will be placed in the sketch folder of the sketch.
  * &lt;p>
  * For more information about Minim and additional features, 
  * visit http://code.compartmental.net/minim/
  */

import ddf.minim.*;
import ddf.minim.ugens.*;

Minim         minim;
AudioOutput   out;
AudioRecorder recorder;

void setup()
{
  size(512, 200, P3D);
  
  minim = new Minim(this);

  out = minim.getLineOut();
  
  // create a recorder that will record from the output to the filename specified
  // the file will be located in the sketch's root folder.
  recorder = minim.createRecorder(out, "myrecording.wav");
  
  // patch some sound into the output so we have something to record
  Oscil wave = new Oscil( 440.f, 1.0f );
  Oscil mod  = new Oscil( 4.0f,  0.25f, Waves.SAW );
  mod.offset.setLastValue( 0.5f );
  mod.patch( wave.amplitude );
  wave.patch( out );
  
  textFont(createFont("Arial", 12));
}

void draw()
{
  background(0); 
  stroke(255);
  // draw the waveforms
  // the values returned by left.get() and right.get() will be between -1 and 1,
  // so we need to scale them up to see the waveform
  for(int i = 0; i &lt; out.bufferSize() - 1; i++)
  {
    line(i, 50  + out.left.get(i)*50,  i+1, 50  + out.left.get(i+1)*50);
    line(i, 150 + out.right.get(i)*50, i+1, 150 + out.right.get(i+1)*50);
  }
  
  if ( recorder.isRecording() )
  {
    text("Currently recording...", 5, 15);
  }
  else
  {
    text("Not recording.", 5, 15);
  }
}

void keyReleased()
{
  if ( key == 'r' ) 
  {
    // to indicate that you want to start or stop capturing audio data, you must call
    // beginRecord() and endRecord() on the AudioRecorder object. You can start and stop
    // as many times as you like, the audio data will be appended to the end of the buffer 
    // (in the case of buffered recording) or to the end of the file (in the case of streamed recording). 
    if ( recorder.isRecording() ) 
    {
      recorder.endRecord();
    }
    else 
    {
      recorder.beginRecord();
    }
  }
  if ( key == 's' )
  {
    // we've filled the file out buffer, 
    // now write it to the file we specified in createRecorder
    // in the case of buffered recording, if the buffer is large, 
    // this will appear to freeze the sketch for sometime
    // in the case of streamed recording, 
    // it will not freeze as the data is already in the file and all that is being done
    // is closing the file.
    // the method returns the recorded audio as an AudioRecording, 
    // see the example  AudioRecorder >> RecordAndPlayback for more about that
    recorder.save();
    println("Done saving.");
  }
}
</pre>
    	
    	<p class="memberSectionHeader">Usage</p>
    	Web & Application
    </td>
  </tr>
</table>
</center>
</body>
</html>
